#include <iostream>

using namespace std;

class Dog{
public:
	static int num;
	int age = 0;
	string name = NULL;
	Dog(int age, string name):age(age),name(name){
		// 进入构造函数之前会先执行初始化列表 为类成员赋值 然后再 执行构造函数的代码
		cout << "init: this age is " << this->age << endl;
	}
	Dog(const Dog& dog):age(dog.age), name(dog.name){
		cout<< "copy constructor." << endl;
	}
	Dog& setAge(int age){
		this->age = age;
		return *this;
	}
	void say(){
		cout << "what a cute dog" << endl;
	}
};
// 如果不定义的话 在使用时会提示 未定义的引用：Dog::num
int Dog::num = 7;
int main(){
	Dog dog(19, "九点零分接送i");
	cout << dog.age << "\t" << dog.name << endl;
	
	cout << "dog num is " << Dog::num << endl;
	
	Dog &dog2 = dog.setAge(23);
	cout << dog2.age << " " << dog2.name << endl;
	
	cout << "&dog = " << &dog << endl;
	cout << "&dog2 = " << &dog2 << endl;

	// 空指针也可以调用成员函数
	//Dog* dog3 = NULL;
	//dog3->say();
	((Dog*)NULL)->say();
	
	cout << "end..." << endl;	
	return 0;
}